var likes,alreadylike, rand, rand2, rand3;
var hasBeenLiked = new Array(10);
var like = new Array(10);

function init(){
	//likes   = Math.floor(Math.random()*50000)-Math.floor(Math.random()*50000);
	
	like[0] = Math.floor(Math.random()*40000)+10000;
	like[1] = Math.floor(Math.random()*40000)+10000;
	like[2] = Math.floor(Math.random()*40000)+10000;
	like.sort();
	
	like[3]   = Math.floor(Math.random()*50000)-Math.floor(Math.random()*50000);
	like[4]   = Math.floor(Math.random()*50000)-Math.floor(Math.random()*50000);
	like[5]   = Math.floor(Math.random()*50000)-Math.floor(Math.random()*50000);
	like[6]   = Math.floor(Math.random()*50000)-Math.floor(Math.random()*50000);
	like[7]   = Math.floor(Math.random()*50000)-Math.floor(Math.random()*50000);
	like[8]   = Math.floor(Math.random()*50000)-Math.floor(Math.random()*50000);
	like[9]   = Math.floor(Math.random()*50000)-Math.floor(Math.random()*50000);
	
	//alreadylike = false;
	
	for(var i=0;i<10;i++){
		hasBeenLiked[i] = false;
		}
	//document.getElementById("likes").innerHTML = likes;
	document.getElementById("like[0]").innerHTML = like[0];
	document.getElementById('like[1]').innerHTML = like[1];
	document.getElementById('like[2]').innerHTML = like[2];
	document.getElementById('like[3]').innerHTML = like[3];
	document.getElementById('like[4]').innerHTML = like[4];
	document.getElementById('like[5]').innerHTML = like[5];
	document.getElementById('like[6]').innerHTML = like[6];
	document.getElementById('like[7]').innerHTML = like[7];
	document.getElementById('like[8]').innerHTML = like[8];
	document.getElementById('like[9]').innerHTML = like[9];
	//alert("Assalamu'alaikum");
	//for(var x = 0;x<10;x++){alert(document.getElementById('like['+x+']').innerHTML);}
}

function initcontent(){
	likes = Math.floor(Math.random()*100001 - 50000);
	alreadylike = false;
	document.getElementById('likes').innerHTML = likes;
}

function commentClick(){
	var name = 'Anonymous';
	var commentcontent = document.getElementById('commenttxt').value;
	var d= new Date();
	var date = d.getDate();
	var month = d.getMonth();
	var year = d.getFullYear();
	var time = d.toLocaleTimeString();
	var commenttime = date + '/' + month + '/' + year + ' ' + 'at ' + time;
	var comments = document.getElementById('commentdiv');
	var commentsHTML = comments.innerHTML;
	comments.innerHTML = '<div class="commentlist"><div class="commentator">' + name + '</div><div class="dateformat">' + commenttime + '</div><div class="commenttext">' + commentcontent + '</div></div>' + commentsHTML;
}
function like(){
	if(alreadylike == false){
		likes++;
		alreadylike = true;
		document.getElementById('likebutton').disabled = true;
		document.getElementById('dislikebutton').disabled = true;
		document.getElementById('likes').innerHTML = likes;
	}
}
function dislike(){
	if(alreadylike == false){
		likes--;
		alreadylike = true;
		document.getElementById('likebutton').disabled = true;
		document.getElementById('dislikebutton').disabled = true;
		document.getElementById('likes').innerHTML = likes;
	}
}

/*Fungsi Like Dislike untuk Halaman Utama*/
function likeID(id){
	if(hasBeenLiked[id] == false){
		like[id]++;
		hasBeenLiked[id] = true;
		document.getElementById("likebutton"+id).disabled = true;
		document.getElementById("dislikebutton"+id).disabled = true;
		document.getElementById("like["+id+"]").innerHTML = like[id];
	}
}
function dislikeID(id){
	if(hasBeenLiked[id] == false){
		like[id]--;
		hasBeenLiked[id] = true;
		document.getElementById("likebutton"+id).disabled = true;
		document.getElementById("dislikebutton"+id).disabled = true;
		document.getElementById("like["+id+"]").innerHTML = like[id];
	}
}
